﻿<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
 
  protected void Page_Load(object sender, EventArgs e)
  { 
    string TrsCode = CommonUtil.GetRequestValue("TrsCode");
    string MerchantKey = CommonUtil.GetRequestValue("MerchantKey");
    string AccountNo = CommonUtil.GetRequestValue("OrderNumber");
    string CurrentOrderNo =
      string.IsNullOrEmpty(AccountNo) ? "" : "20" + AccountNo.Substring(4, 6) + "0" + AccountNo.Substring(10, 3);
   
    if (TrsCode != "0000")
    {
      TransactionFail("系統下單失敗!! 很抱歉，銀行通知扣款失敗，麻煩您再試一次或重新訂購並變更付款方式，謝謝惠顧！");
    }
    else
    {
      string CurrentBuyerName = (string)Session["CurrentBuyerName"];
      //清空購買人
      Session.Remove("CurrentBuyerName");
      //清空購物車          
      Session.Remove("ShoppingCart");
      //清空訂單資訊
      Session.Remove("OrderInfo");
      //清空加贈
      Session.Remove("FreePlusItem");
      //清空加購
      Session.Remove("BuyPlusItem");
      //導向訂單完成                    
      NameValueCollection data = new NameValueCollection();
      data.Add("CurrentOrderNo", CurrentOrderNo);
      data.Add("CurrentBuyerName", CurrentBuyerName);
      HttpHelper.RedirectAndPOST(this.Page, Page.ResolveUrl("~/Orders/ConfirmOrder.aspx"), data);
    }
  }

  protected void TransactionFail(string Message)
  {
    //交易失敗，若WEBATM不成功，則導回下單頁
    Page.ClientScript.RegisterStartupScript(this.GetType(),
            "交易失敗",
            "alert('" + Message + "');"
            + "document.location='OrderComplete.aspx'",
            true);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>長榮樂e購</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
    </div>
  </form>
</body>
</html>
